package com.liupf.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.liupf.domain.Tel;
import com.liupf.domain.UserPoint;

public class UserPointController extends Controller{

	public void index(){
		int userid=(int)getSession().getAttribute("userId");
		String sql="from user_point where userid="+userid;
		
		 Page<UserPoint> page=UserPoint.dao.paginate(getParaToInt(0, 1), 10,
		            "select  * ", sql);
		 
		 setAttr("page", page);
		 render("userpoint.ftl");
	}
	
	public void delete(){
		String id=getPara();
		UserPoint.dao.deleteById(id);
		
		redirect("/userpoint");
	}
	
	public void save(){
		UserPoint point=getModel(UserPoint.class);
		int userid=(int)getSession().getAttribute("userId");
		point.set("userid", userid);
		point.save();
		
		redirect("/userpoint");
	}
	
	public void edit(){
		UserPoint point=getModel(UserPoint.class);
		point.update();
		
		redirect("/userpoint");
	}
	
	public void add(){
		render("userpoint_add.ftl");
	}
	
	public void toEdit(){
		UserPoint point=UserPoint.dao.findById(getPara());
		
		 setAttr("userpoint", point);
		 render("userpoint_edit.ftl");
	}
	
}
